feat: Make ASGI support span first#5680
Merged
sentrivana merged 8 commits intomasterfrom Mar 19, 2026
Merged
Conversation
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.85s All tests are passing successfully. ❌ Patch coverage is 6.25%. Project has 14372 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
alexander-alderman-webb
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR makes the ASGI integration work both in legacy and span streaming mode. Some features and attributes will be missing in span streaming mode for now (see the Out of scope section below).
Best reviewed with whitespace ignored: https://github.com/getsentry/sentry-python/pull/5680/changes?w=1
A bit of a background on migrating integrations to span first. In order to support both legacy spans and span streaming, most integrations will follow the same patterns:
API
We need to use the
start_spanAPI fromsentry_sdk.tracesif we're in span streaming mode (traces_lifecycle="stream").There are no transactions anymore. Top-level spans will also be started via the
start_spanAPI in span streaming mode.Setting data on spans
If an integration sets data on a span (via
span.set_data,span.set_tagetc.), it should usespan.set_attributewhen span streaming is enabled.The attributes that we set need to be in Sentry conventions. This is deliberately not the case for most quick ports of integrations like this one and will follow in a future step.
Trace propagation
If an integration sits at a service boundary and is capable of propagating incoming trace information (like WSGI/ASGI or Celery), in span first mode we need to switch from the old style
with continue_trace(...) as transaction:to the new stylecontinue_trace()andnew_trace()(not context managers).start_spanargumentsYou can pass things like
op,origin,sourceto the oldstart_spanAPI. With the new API, this is no longer possible, and the individual properties need to be set as attributes directly.Out of scope
For now, the following is out of scope and will follow in the future: